<template>
  <div class="Home">
    <div class="box">
      <!-- 走马灯 -->
      <div class="WalkingLantern">
        <el-carousel height="600px" indicator-position="outside">
          <el-carousel-item v-for="item in Lanterns" :key="item.id">
            <img class="small film" :src="item.url" />
          </el-carousel-item>
        </el-carousel>
      </div>

      <!-- 内容 -->
      <div class="Section">
        <!-- 电影展示 -->
        <div class="SectionLeft">
          <span>热门电影</span>
          <ul>
            <li
              v-for="item in films"
              :key="item.id"
              @click="gotoDetail(item.id)"
            >
              <div>
                <div class="Films">
                  <img :src="item.cover" alt="" />
                  <div class="FilmName">
                    <span>{{ item.name }}</span>
                  </div>
                </div>
                <span>{{ item.hot }}人想看</span>
                <span>{{ item.releaseTime }}上映</span>
              </div>
            </li>
          </ul>
        </div>
        <!-- TOP10电影榜单 -->
        <div class="SectionRight">
          <span>热门榜单TOP10</span>
          <!-- Top1 -->
          <div class="TopOne" @click="gotoDetail(Topone.id)">
            <img :src="Topone.cover" />
            <span>{{ Topone.name }}</span>
            <span>上映时间:{{ Topone.releaseTime }}</span>
            <span>热度值:{{ Topone.hot }}</span>
          </div>
          <!-- Top2 & 3 -->
          <div
            v-for="(film, index) in Toptt"
            :key="index"
            @click="gotoDetail(film.id)"
            class="TwoAndThree"
          >
            <img :src="film.cover" alt="123" />
            <br />
            <span>{{ film.name }}</span>
            <span>热度值:{{ film.hot }}</span>
          </div>
          <div class="clear"></div>
          <!-- TopLater -->
          <div
            v-for="(item, index) in TopLater"
            :key="index + 4"
            @click="gotoDetail(item.id)"
            class="toplater"
          >
            <span>{{ index + 4 }}</span>
            <span>{{ item.name }}</span>
            <span>热度值:{{ item.hot }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { ListAllPoster, nowplaying, hotfilm } from "@/api/user.js";
export default {
  name: "Home",
  data() {
    return {
      Lanterns: [],
      films: [],
      Topone: {},
      Toptt: [],
      TopLater: [],
    };
  },
  components: {},
  methods: {
    // 轮播图
    posterQuery() {
      ListAllPoster().then((res) => {
        if (res.code === 200) {
          this.Lanterns = res.data;
        }
      });
    },

    // 查询电影列表
    getnowplaying() {
      nowplaying("全部", "全部").then((res) => {
        if (res.code === 200) {
          this.films = res.data;
        }
      });
    },

    gethotfilm() {
      hotfilm(10).then((res) => {
        if (res.code === 200) {
          this.Topone = res.data[0];
          this.Toptt = res.data.slice(1, 3);
          this.TopLater = res.data.slice(3);
        }
      });
    },
    gotoDetail(id) {
      this.$router.push({
        path: "/index/Details",
        query: {
          id,
        },
      });
    },
  },
  mounted() {
    this.posterQuery();
    this.getnowplaying();
    this.gethotfilm();
  },
};
</script>

<style lang="less" scoped>
.Home {
  margin: 0;
  padding: 0;
  width: 100%;
  .box {
    margin: 40px auto;
    width: 1440px;
    // 清除浮动
    .clear {
      clear: both;
    }
    // 走马灯
    .WalkingLantern {
      height: 600px;
      img {
        width: 1440px;
      }
    }

    // 内容样式
    .Section {
      margin-top: 50px;
      width: 100%;
      display: flex;
      justify-content: space-around;
      .SectionLeft {
        span:nth-child(1) {
          display: block;
          color: gold;
          font-size: 25px;
          margin: 20px 0 0 20px;
        }
        width: 55%;
        overflow: hidden;
        ul {
          display: flex;
          justify-content: left;
          flex-wrap: wrap;
          list-style: none;
          li {
            margin: 10px 0 0 15px;
            cursor: pointer;
            div:nth-child(1) {
              width: 180px;
              height: 310px;
              .Films {
                position: relative;
                height: 251px;
                overflow: hidden;
                img {
                  width: 180px;
                  height: 251px;
                }
                .FilmName {
                  width: 100%;
                  height: 45px;
                  opacity: 0.7;
                  background-color: black;
                  position: absolute;
                  bottom: -45px;
                  transition: 0.3s;
                  span {
                    display: block;
                    margin: 10px 0 0 10px;
                    color: white;
                    font-size: 16px;
                  }
                }
              }
              span:nth-child(2) {
                float: left;
                color: orange;
              }
              span:nth-child(3) {
                display: block;
                margin: 10px 10px 0 0;
                float: right;
                color: gray;
                font-size: 14px;
              }
            }
          }
          li:hover div > .Films > .FilmName {
            bottom: 0px;
          }
        }
      }
      .SectionRight {
        margin-top: 15px;
        width: 30%;
        span:nth-child(1) {
          color: gold;
          font-size: 25px;
        }
        .TopOne {
          margin-top: 15px;
          cursor: pointer;
          position: relative;
          width: 400px;
          img {
            height: 200px;
          }
          span {
            position: absolute;
            color: gray;
          }
          span:nth-child(2) {
            left: 45%;
            top: 25%;
            font-size: 25px;
          }
          span:nth-child(3) {
            left: 45%;
            top: 40%;
            font-size: 20px;
          }
          span:nth-child(4) {
            left: 45%;
            top: 60%;
            color: gold;
            font-size: 13px;
          }
        }
        .TopOne:hover span,
        .TwoAndThree:hover span,
        .toplater:hover span {
          opacity: 0.5;
        }
        .TwoAndThree {
          cursor: pointer;
          float: left;
          margin: 10px 10px 20px 0;
          height: 260px;
          position: relative;
          img {
            height: 200px;
          }
          span {
            position: absolute;
            left: 5%;
          }
          span:nth-child(3) {
            font-size: 20px;
            top: 80%;
            color: gray;
          }
          span:nth-child(4) {
            color: gold;
            font-size: 13px;
            bottom: 0;
          }
        }
        .toplater {
          cursor: pointer;
          margin-top: 20px;
          width: 370px;
          span:nth-child(1) {
            display: block;
            font-size: 16px;
            color: gray;
            float: left;
            width: 20px;
            text-align: center;
          }
          span:nth-child(2) {
            display: inline-block;
            margin-left: 10px;
            font-size: 16px;
          }
          span:nth-child(3) {
            display: block;
            float: right;
            color: gold;
            font-size: 13px;
          }
        }
      }
    }
  }
}
</style>